/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-11-27     Administrator       the first version
 */

/*
 * Motion control is achieved through motor management files,
 * motor management includes marking position management.
 * This means that each motor keeps some information, the
 * motor is still managed separately, and the motor management
 * is just adding some management operations to the original
 * motion control. To facilitate the motor action sequence better call.
 */

#include "MotionManage.h"
#include "Motion.h"



#include <rtthread.h>
#include <rtdbg.h>


rt_uint32_t PosInfo[200];
MotionManage DummyMotor[40];
MotionManage *DummyMotorPtr[40];

//
MotionManage::MotionManage()
{

}
//
MotionManage::~MotionManage()
{

}

/*
* Function name: ~ActionQueue()
* Input argv:
*      --
* Output argv:
*      --
* Return:
       true: success
       false: fail
* Function Description:  the destructor
* Version: 1.0
* Be careful:
*/
rt_uint32_t MotionManage::GetPosInfo(rt_uint8_t posNo)
{
    return CalibratInfo[posNo];
}

/*
* Function name: DummyMotorInit()
* Input argv:
*      void
* Output argv:
*      void
* Return:
       void
* Function Description:
*       Build and map hardware drives.
* Version: 1.0
* Be careful:
*/
void DummyMotorInit()
{
    for (rt_uint8_t i = 1; i <= MOTOR_TOTAL_NUM; i++)
    {
        if(MyBoardMotor(i) == true)
        {
            rt_uint8_t dirver_num = MotorDiverNum(i);
            if(dirver_num > 0 && dirver_num <= 6)
            {
                DummyMotorPtr[i] = (MotionManage *)&tmc_driver[dirver_num];
                LOG_D("Dummy motor named %s numbered %d is find its motor dirver %d.",
                        motor_info[i].name,
                        i,
                        dirver_num);
            }
            else
            {

            }
        }
        else
        {
            //LOG_D("");
        }
    }
}

bool MyBoardMotor(rt_uint8_t motor_num)
{
    if(machine_info.addr == motor_info[motor_num].board_addr)
        return true;
    else
        return false;
}

rt_uint8_t MotorDiverNum(rt_uint8_t motor_num)
{
    //if(machine_info.addr == motor_info[motor_num].board_addr)
    {
        return motor_info[motor_num].dirver_num;
    }
    return 1;
}



bool haveLiquiedDetection(rt_uint8_t motor_num)
{
    //if(machine_info.addr == motor_info[motor_num].board_addr)
    {
        return motor_info[motor_num].liquied_det;
    }
    return 0;
}
